﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InkFx.SF.UI;
using InkFx.WinControl;
using InkFx.WinControl.Core;
using Temp_20210321_AForm9.Properties;

namespace Temp_20190707_AForm
{
    public partial class Form1 : System.Windows.Forms.Form
    {
        public Form1()
        {
            InitializeComponent();
            //this.button7.Click += new System.EventHandler(this.button7_Click);
            //this.button8.Click += new System.EventHandler(this.button8_Click);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var panel = RandomControl();
            dockPanel1.DoDock(panel, XIDEAlignment.Center, XIDEGroupState.Expand);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            button2_Click(sender, e);
            //dockPanel1.ShowDLPanel(null);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //dockPanel1.HideDLPanel();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            var panel = RandomControl();
            dockPanel1.DoDock(panel, XIDEAlignment.Left, XIDEGroupState.Float);
        }
        private void button4_Click(object sender, EventArgs e)
        {
            this.dockPanel1.ResetLayout();
            var listSplit = this.dockPanel1.GetListSplit();
            var listGroup = this.dockPanel1.GetListGroup();
            var listFrame = this.dockPanel1.GetListFrame();

            MessageBox.Show(string.Format("Split 总数: {0}, Group 总数: {1}, Frame 总数: {2} \r\n\r\nPadding: {3} \r\n", listSplit.Count, listGroup.Count, listFrame.Count, dockPanel1.Padding));
        }
        private void button5_Click(object sender, EventArgs e)
        {
            var panel左上0 = RandomControl();
            var panel左上1 = RandomControl();
            var panel左下0 = RandomControl();
            var panel左下1 = RandomControl();
            var panel左下2 = RandomControl();
            var panel右0 = RandomControl();
            var panel下0 = RandomControl();
            var panel下1 = RandomControl();

            var panel文档上0 = RandomControl();
            var panel文档上1 = RandomControl();
            var panel文档上2 = RandomControl();
            var panel文档上3 = RandomControl();

            var panel文档下0 = RandomControl();
            var panel文档下1 = RandomControl();
            var panel文档下2 = RandomControl();

            XIDEGroup group左上 = dockPanel1.DoDock(panel左上0, XIDEAlignment.Left);
            group左上.DoDock(panel左上1, XIDEAlignment.Center);

            XIDEGroup group左下 = group左上.DoDock(panel左下0, XIDEAlignment.Bottom);
            group左下.DoDock(panel左下1, XIDEAlignment.Center);
            group左下.DoDock(panel左下2, XIDEAlignment.Center);

            XIDEGroup group右 = dockPanel1.DoDock(panel右0, XIDEAlignment.Right);

            XIDEGroup group下 = dockPanel1.DoDock(panel下0, XIDEAlignment.Bottom);
            group下.DoDock(panel下1, XIDEAlignment.Center);


            XIDEGroup group文档上 = dockPanel1.DoDock(panel文档上0, XIDEAlignment.Center, XIDEGroupState.Expand);
            group文档上.DoDock(panel文档上1, XIDEAlignment.Center);
            group文档上.DoDock(panel文档上2, XIDEAlignment.Center);
            group文档上.DoDock(panel文档上3, XIDEAlignment.Center);

            XIDEGroup group文档下 = group文档上.DoDock(panel文档下0, XIDEAlignment.Bottom);
            group文档下.DoDock(panel文档下1, XIDEAlignment.Center);
            group文档下.DoDock(panel文档下2, XIDEAlignment.Center);
        }
        private void button6_Click(object sender, EventArgs e)
        {
            AssemblyForm panel = new AssemblyForm();
            panel.Icon = Resources.Control;
            panel.BackColor = RandomColor();
            dockPanel1.DoDock(panel, XIDEAlignment.Bottom);
        }
        //private void button7_Click(object sender, EventArgs e)
        //{
        //    int style = Win32API.GetWindowLong(dockPanel1.Handle, GWLIndex.GWL_EXSTYLE);
        //    style = style | (int)WindowStyles.WS_CLIPCHILDREN;
        //    Win32API.SetWindowLong(dockPanel1.Handle, GWLIndex.GWL_EXSTYLE, style);
        //    //dockPanel1.Refresh();
        //}
        //private void button8_Click(object sender, EventArgs e)
        //{
        //    int style = Win32API.GetWindowLong(dockPanel1.Handle, GWLIndex.GWL_EXSTYLE);
        //    style = style & ~(int)WindowStyles.WS_CLIPCHILDREN;
        //    Win32API.SetWindowLong(dockPanel1.Handle, GWLIndex.GWL_EXSTYLE, style);
        //    //dockPanel1.Refresh();
        //}


        private static int i = 0;
        public static XIDETempFrame RandomControl()
        {
            XIDETempFrame panel = new XIDETempFrame();
            panel.Text = "测试面板" + (i++).ToString().PadLeft(2, '0');
            panel.Icon = Resources.Control;
            TextBox box = new TextBox();
            box.Location = new Point(10, 10);
            box.Parent = panel;
            panel.BackColor = RandomColor();
            return panel;
        }
        public static Color RandomColor()
        {
            return Color.FromArgb(new Random(Guid.NewGuid().GetHashCode()).Next(0, 256), new Random(Guid.NewGuid().GetHashCode()).Next(0, 256), new Random(Guid.NewGuid().GetHashCode()).Next(0, 256));
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //e.Cancel = false;
            Console.WriteLine("Form1_FormClosing");
        }
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Console.WriteLine("Form1_FormClosed");
        }







    }

    public class XIDETempFrame : XIDEFrame
    {
        public override XIDEFrameReleaseMode GetReleaseMode()
        {
            return XIDEFrameReleaseMode.Dispose;
        }
    }
}
